﻿using System;
using System.Collections.Generic;
using System.Text;
using Zove.Runtime;
using System.Windows.Media.Media3D;

namespace WPF3DTutorial.Model {
    public abstract class AbstractModelVisualizer : IModelVisualizer {

        protected Solution solution = null;

        protected Window1 window = null;

        public AbstractModelVisualizer(Window1 window) {
            this.window = window;
        }

        public Model3DGroup Draw(string criteria) {
            this.solution.Reset();
            this.UpdateModel(criteria);
            return this.Draw();
        }

        public abstract Model3DGroup Draw();

        protected void UpdateModel(string criteria) {
            string[] criterion = criteria.Split(';');

            foreach (string stmt in criterion) {
                string[] s = stmt.Split('=');

                string factorName = s[0].Trim();
                string value = s[1].Trim();

                RuntimeFactor rf = this.solution.Model.GetFactorByName(factorName);
                rf.Status = RuntimeFactorStatus.Input;
                rf.Value = Convert.ToDouble(value);
            }

            this.solution.Solve();
        }
    }
}
